package com.example.oauthserver.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
@RequestMapping(value = "/users")
@Slf4j
public class UserController {

    @GetMapping(value = "/current",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Principal> getUser(Principal principal){
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        log.info(JSONObject.toJSONString(principal,true));
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        return new ResponseEntity<>(principal, HttpStatus.OK);
    }
}
